package com.capricorn.orion.messagebot;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	private Intent serviceIntent = null;
	
	// Button Click Listener
	private OnClickListener buttonOnClickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			Button button = (Button) v;
			if (button == null) {
				return;
			}

			switch (button.getId()) {
			case R.id.startServiceButton:
				serviceIntent = new Intent(v.getContext(), MessageBotService.class);
				startService(serviceIntent);
				break;
			case R.id.stopServiceButton:
				if (serviceIntent != null) {
					stopService(serviceIntent);
					serviceIntent = null;
				}
				break;
			}
		}
	};
	
	private void registerOnClickListener(View v, OnClickListener l) {
		v.setOnClickListener(l);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_main);
		
		registerOnClickListener(findViewById(R.id.startServiceButton),
				buttonOnClickListener);
		registerOnClickListener(findViewById(R.id.stopServiceButton),
				buttonOnClickListener);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
